/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.cadi.games;

import com.cadi.aux.Coin;
import com.cadi.aux.Window;
import com.cadi.menu.MainMenu;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JOptionPane;

/**
 *
 * @author Vercetti
 */
public class Compare extends Window{
    
    private final JLabel instruction,bag1, bag2;
    private Coin[] morlaco;
    boolean bag1Goal;
    private int currentLevel;
    
    public Compare(){
        currentLevel = 1;
        voice = java.applet.Applet.newAudioClip(getClass().getResource("/resources/compara1.wav"));
        voice.play();
        instruction = new JLabel(new ImageIcon(getClass().getResource("/resources/compare_instruction.png")));
        instruction.setBounds(150, 300, 200, 162);
        background.setIcon(new ImageIcon(getClass().getResource("/resources/fondo7.png")));
        bag1 = new JLabel(new ImageIcon(getClass().getResource("/resources/bolsa.png")));
        bag2 = new JLabel(new ImageIcon(getClass().getResource("/resources/bolsa.png")));
        bag1.setBounds(350, 100, 325, 464);
        bag2.setBounds(850, 100, 325, 464);
        bag1.addMouseListener(new MouseAdapter() {
            @Override
           public void mouseClicked(MouseEvent evt){
                    if(bag1Goal){
                        result = java.applet.Applet.newAudioClip(getClass().getResource("/resources/bien.wav"));
                        result.play(); 
                        JOptionPane.showMessageDialog(container, "¡Bien Hecho!", "¡Bien Hecho!",JOptionPane.INFORMATION_MESSAGE,new ImageIcon(getClass().getResource("/resources/right.png")));
                        setNextLevel();
                    }else{
                        result = java.applet.Applet.newAudioClip(getClass().getResource("/resources/mal.wav"));
                        result.play();
                        JOptionPane.showMessageDialog(container,"Intenta de Nuevo","Intenta de Nuevo",JOptionPane.INFORMATION_MESSAGE,new ImageIcon(getClass().getResource("/resources/wrong.png")));
                    }
          }
        });
        bag2.addMouseListener(new MouseAdapter() {
            @Override
           public void mouseClicked(MouseEvent evt){
                    if(!bag1Goal){
                         JOptionPane.showMessageDialog(container, "¡Bien Hecho!", "¡Bien Hecho!",JOptionPane.INFORMATION_MESSAGE,new ImageIcon(getClass().getResource("/resources/right.png")));
                         setNextLevel();
                    }else{
                        JOptionPane.showMessageDialog(container,"Intenta de Nuevo","Intenta de Nuevo",JOptionPane.INFORMATION_MESSAGE,new ImageIcon(getClass().getResource("/resources/wrong.png")));
                    }
          }
        });
        morlaco = new Coin[8];
        morlaco[1] = new Coin(1, "small");
        morlaco[2] = new Coin(0, "small");
        morlaco[5] = new Coin(1, "small");
        morlaco[6] = new Coin(1, "small");
        morlaco[1].setBounds(400, 325, 75, 75);
        morlaco[2].setBounds(520, 400, 75, 75);
        morlaco[5].setBounds(1010, 310, 75, 75);
        morlaco[6].setBounds(930, 400, 75, 75);
        for(int i = 0;i<8;i++){
            if(i!= 0 && i!= 3 && i!= 4 && i!= 7){
               container.add(morlaco[i],JLayeredPane.MODAL_LAYER); 
            }
        }
        container.add(instruction, JLayeredPane.PALETTE_LAYER);
        container.add(bag1,JLayeredPane.PALETTE_LAYER);
        container.add(bag2,JLayeredPane.PALETTE_LAYER);
        bag1Goal = false;
        window.setVisible(true);
    }
    
    
    private void setNextLevel(){
        currentLevel++;
        switch(currentLevel){
            case 2:
                setLevelTwoEasy();
                break;
            case 3:
                setLevelThreeEasy();
                break;
            case 4:
                setLevelFourEasy();
                break;
            case 5:
                setLevelFiveEasy();
                break;
            case 6:
                MainMenu mainMenu = new MainMenu();
                window.setVisible(false);
                break;
            case 12:
                setLevelTwoInt();
                break;
            case 13:
                setLevelThreeInt();
                break;
            case 14:
                setLevelFourInt();
                break;
            case 15:
                setLevelFiveInt();
                break;
            case 16:
                MainMenu main = new MainMenu();
                window.setVisible(false);
                break;
        }
    }

    private void setLevelTwoEasy() {
        for(int i = 0; i<8;i++){
            if(i!= 0 && i!= 3 && i!= 4 && i!= 7){
                container.remove(morlaco[i]);
                morlaco[i] = null;
            }
        }
        morlaco[1] = new Coin(1, "small");
        morlaco[2] = new Coin(2, "small");
        morlaco[3] = new Coin(1, "small");
        
        morlaco[5] = new Coin(1, "small");
        morlaco[6] = new Coin(1, "small");
        morlaco[7] = new Coin(1, "small");
        morlaco[1].setBounds(400, 325, 75, 75);
        morlaco[2].setBounds(520, 400, 75, 75);
        morlaco[3].setBounds(430, 450, 75, 75);
        morlaco[5].setBounds(1010, 310, 75, 75);
        morlaco[6].setBounds(930, 400, 75, 75);
        morlaco[7].setBounds(1020, 450, 75, 75);
        for(int i = 0;i<8;i++){
            if(i!= 0 && i!= 4){
               container.add(morlaco[i],JLayeredPane.MODAL_LAYER); 
            }
        }
        bag1Goal = true;
        window.repaint();
        voice.play();
    }

    private void setLevelThreeEasy() {
        for(int i = 0;i<8;i++){
            if(i!= 0 && i!= 4){
               container.remove(morlaco[i]);
               morlaco[i] = null; 
            }
        }
        morlaco[0] = new Coin(1, "small");
        morlaco[1] = new Coin(1, "small");
        morlaco[2] = new Coin(2, "small");
        morlaco[3] = new Coin(1, "small");
        
        morlaco[4] = new Coin(2, "small");
        morlaco[5] = new Coin(1, "small");
        morlaco[6] = new Coin(0, "small");
        morlaco[7] = new Coin(1, "small");
        morlaco[0].setBounds(500, 270, 75, 75);
        morlaco[1].setBounds(400, 325, 75, 75);
        morlaco[2].setBounds(520, 400, 75, 75);
        morlaco[3].setBounds(430, 450, 75, 75);
        
        morlaco[4].setBounds(900, 270, 75, 75);
        morlaco[5].setBounds(1010, 310, 75, 75);
        morlaco[6].setBounds(930, 400, 75, 75);
        morlaco[7].setBounds(1020, 450, 75, 75);
        for(int i = 0;i<8;i++){
            container.add(morlaco[i],JLayeredPane.MODAL_LAYER); 
        }
        window.repaint();
        voice.play();
    }

    private void setLevelFourEasy() {
        for(int i = 0;i<8;i++){
           container.remove(morlaco[i]);
           morlaco[i] = null;
        }
        morlaco[0] = new Coin(2, "small");
        morlaco[1] = new Coin(1, "small");
        morlaco[2] = new Coin(0, "small");
        morlaco[3] = new Coin(1, "small");
        
        morlaco[4] = new Coin(2, "small");
        morlaco[5] = new Coin(2, "small");
        morlaco[6] = new Coin(2, "small");
        morlaco[7] = new Coin(1, "small");
        morlaco[0].setBounds(500, 270, 75, 75);
        morlaco[1].setBounds(400, 325, 75, 75);
        morlaco[2].setBounds(520, 400, 75, 75);
        morlaco[3].setBounds(430, 450, 75, 75);
        
        morlaco[4].setBounds(900, 270, 75, 75);
        morlaco[5].setBounds(1010, 310, 75, 75);
        morlaco[6].setBounds(930, 400, 75, 75);
        morlaco[7].setBounds(1020, 450, 75, 75);
        for(int i = 0;i<8;i++){
            container.add(morlaco[i],JLayeredPane.MODAL_LAYER); 
        }
        bag1Goal = false;
        window.repaint();
        voice.play();
    }

    private void setLevelFiveEasy() {
        for(int i = 0;i<8;i++){
           container.remove(morlaco[i]);
           morlaco[i] = null;
        }
        morlaco[0] = new Coin(1, "small");
        morlaco[1] = new Coin(5, "small");
        morlaco[2] = new Coin(2, "small");
        morlaco[3] = new Coin(1, "small");
        
        morlaco[4] = new Coin(2, "small");
        morlaco[5] = new Coin(2, "small");
        morlaco[6] = new Coin(5, "small");
        morlaco[7] = new Coin(1, "small");
        morlaco[0].setBounds(500, 270, 75, 75);
        morlaco[1].setBounds(400, 325, 75, 75);
        morlaco[2].setBounds(520, 400, 75, 75);
        morlaco[3].setBounds(430, 450, 75, 75);
        
        morlaco[4].setBounds(900, 270, 75, 75);
        morlaco[5].setBounds(1010, 310, 75, 75);
        morlaco[6].setBounds(930, 400, 75, 75);
        morlaco[7].setBounds(1020, 450, 75, 75);
        for(int i = 0;i<8;i++){
            container.add(morlaco[i],JLayeredPane.MODAL_LAYER); 
        }
        bag1Goal = false;
        window.repaint();
        voice.play();
    }
    
    public void setLevelOneInt(){
        currentLevel = 11;
        for(int i = 0; i<8;i++){
            if(i!= 0 && i!= 3 && i!= 4 && i!= 7){
                container.remove(morlaco[i]);
                morlaco[i] = null;
            }
        }
        morlaco[0] = new Coin(10, "small");
        morlaco[1] = new Coin(5, "small");
        morlaco[2] = new Coin(20, "small");
        morlaco[3] = new Coin(1, "small");
        
        morlaco[4] = new Coin(20, "small");
        morlaco[5] = new Coin(10, "small");
        morlaco[6] = new Coin(2, "small");
        morlaco[7] = new Coin(1, "small");
        morlaco[0].setBounds(500, 270, 75, 75);
        morlaco[1].setBounds(400, 325, 75, 75);
        morlaco[2].setBounds(520, 400, 75, 75);
        morlaco[3].setBounds(430, 450, 75, 75);
        
        morlaco[4].setBounds(900, 270, 75, 75);
        morlaco[5].setBounds(1010, 310, 75, 75);
        morlaco[6].setBounds(930, 400, 75, 75);
        morlaco[7].setBounds(1020, 450, 75, 75);
        for(int i = 0;i<8;i++){
            container.add(morlaco[i],JLayeredPane.MODAL_LAYER); 
        }
        bag1Goal = true;
        window.repaint();
        voice.play();
    }

    private void setLevelTwoInt() {
        for(int i = 0;i<8;i++){
           container.remove(morlaco[i]);
           morlaco[i] = null;
        }
        morlaco[0] = new Coin(50, "small");
        morlaco[1] = new Coin(1, "small");
        morlaco[2] = new Coin(2, "small");
        morlaco[3] = new Coin(1, "small");
        
        morlaco[4] = new Coin(10, "small");
        morlaco[5] = new Coin(20, "small");
        morlaco[6] = new Coin(20, "small");
        morlaco[7] = new Coin(5, "small");
        morlaco[0].setBounds(500, 270, 75, 75);
        morlaco[1].setBounds(400, 325, 75, 75);
        morlaco[2].setBounds(520, 400, 75, 75);
        morlaco[3].setBounds(430, 450, 75, 75);
        
        morlaco[4].setBounds(900, 270, 75, 75);
        morlaco[5].setBounds(1010, 310, 75, 75);
        morlaco[6].setBounds(930, 400, 75, 75);
        morlaco[7].setBounds(1020, 450, 75, 75);
        for(int i = 0;i<8;i++){
            container.add(morlaco[i],JLayeredPane.MODAL_LAYER); 
        }
        bag1Goal = false;
        window.repaint();
        voice.play();
    }

    private void setLevelThreeInt() {
        for(int i = 0;i<8;i++){
           container.remove(morlaco[i]);
           morlaco[i] = null;
        }
        morlaco[0] = new Coin(50, "small");
        morlaco[1] = new Coin(20, "small");
        morlaco[2] = new Coin(10, "small");
        morlaco[3] = new Coin(5, "small");
        
        morlaco[4] = new Coin(50, "small");
        morlaco[5] = new Coin(20, "small");
        morlaco[6] = new Coin(20, "small");
        morlaco[7] = new Coin(5, "small");
        morlaco[0].setBounds(500, 270, 75, 75);
        morlaco[1].setBounds(400, 325, 75, 75);
        morlaco[2].setBounds(520, 400, 75, 75);
        morlaco[3].setBounds(430, 450, 75, 75);
        
        morlaco[4].setBounds(900, 270, 75, 75);
        morlaco[5].setBounds(1010, 310, 75, 75);
        morlaco[6].setBounds(930, 400, 75, 75);
        morlaco[7].setBounds(1020, 450, 75, 75);
        for(int i = 0;i<8;i++){
            container.add(morlaco[i],JLayeredPane.MODAL_LAYER); 
        }
        bag1Goal = false;
        window.repaint();
        voice.play();
    }

    private void setLevelFourInt() {
        for(int i = 0;i<8;i++){
           container.remove(morlaco[i]);
           morlaco[i] = null;
        }
        morlaco[0] = new Coin(200, "small");
        morlaco[1] = new Coin(100, "small");
        morlaco[2] = new Coin(10, "small");
        morlaco[3] = new Coin(50, "small");
        
        morlaco[4] = new Coin(200, "small");
        morlaco[5] = new Coin(100, "small");
        morlaco[6] = new Coin(50, "small");
        morlaco[7] = new Coin(5, "small");
        morlaco[0].setBounds(500, 270, 75, 75);
        morlaco[1].setBounds(400, 325, 75, 75);
        morlaco[2].setBounds(520, 400, 75, 75);
        morlaco[3].setBounds(430, 450, 75, 75);
        
        morlaco[4].setBounds(900, 270, 75, 75);
        morlaco[5].setBounds(1010, 310, 75, 75);
        morlaco[6].setBounds(930, 400, 75, 75);
        morlaco[7].setBounds(1020, 450, 75, 75);
        for(int i = 0;i<8;i++){
            container.add(morlaco[i],JLayeredPane.MODAL_LAYER); 
        }
        bag1Goal = true;
        window.repaint();
        voice.play();
    }

    private void setLevelFiveInt() {
        for(int i = 0;i<8;i++){
           container.remove(morlaco[i]);
           morlaco[i] = null;
        }
        morlaco[0] = new Coin(500, "small");
        morlaco[1] = new Coin(200, "small");
        morlaco[2] = new Coin(20, "small");
        morlaco[3] = new Coin(50, "small");
        
        morlaco[4] = new Coin(500, "small");
        morlaco[5] = new Coin(200, "small");
        morlaco[6] = new Coin(100, "small");
        morlaco[7] = new Coin(20, "small");
        morlaco[0].setBounds(500, 270, 75, 75);
        morlaco[1].setBounds(400, 325, 75, 75);
        morlaco[2].setBounds(520, 400, 75, 75);
        morlaco[3].setBounds(430, 450, 75, 75);
        
        morlaco[4].setBounds(900, 270, 75, 75);
        morlaco[5].setBounds(1010, 310, 75, 75);
        morlaco[6].setBounds(930, 400, 75, 75);
        morlaco[7].setBounds(1020, 450, 75, 75);
        for(int i = 0;i<8;i++){
            container.add(morlaco[i],JLayeredPane.MODAL_LAYER); 
        }
        bag1Goal = false;
        window.repaint();
        voice.play();
    }
}
